<template>
  <div class="vue-box sbot-fluid sbot">
    <div class="c-panel">
      <el-form :inline="true">
        <!-- no字段： m.id - id -->
        <sa-item v-model="m.name" type="text" name="角色名" br />
        <sa-item v-model="m.level" type="enum" jtype="3" :jv="dims.ROLE_LEVEL" name="角色等级" br />
        <sa-item v-model="m.status" type="enum" jtype="3" :jv="dims.YES_OR_NO" name="启用状态" :disabled="m.isLock === 1"
          br />
        <sa-item v-model="m.sort" type="text" name="序号" br />
        <sa-item v-model="m.note" type="text" name="角色描述" br />

        <sa-item name="" class="s-ok" br>
          <el-button type="primary" icon="el-icon-plus" @click="ok()">保存</el-button>
        </sa-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: 'role-update',
  props: { param: Object },
  data() {
    return {
      // 超级对象
      m: this.createModel(),
      dims: this.param.dims
    }
  },
  created: function () {
  },
  methods: {
    // 创建一个 默认Model
    createModel() {
      return {
        id: this.param.id,
        name: this.param.name,
        level: this.param.level,
        sort: this.param.sort,
        note: this.param.note,
        isLock: this.param.isLock,
        status: this.param.status,
      }
    },
    // 提交数据
    ok: function () {
      // 验证 获取 m对象
      let m = this.m;
      sa.checkNull(m.name, '请输入角色名字');

      // 开始增加
      sa.ajax('/role/update', this.m, function (res) {
        sa.alert('角色变更成功', function () {
          this.m = this.createModel();
          sa.closeModel();
          sa.currView().f5();
        }.bind(this));
      }.bind(this));
    },
  }
}
</script>

<style scoped></style>
